﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using NancyOauth2.Utils;

namespace NancyOauth2.Models
{
    public class AuthorizeModel:BaseModel
    {
    }

    /// <summary>
    /// 授权不成功的模型
    /// </summary>
    public class AuthErrorModel : BaseModel
    {
        private ErrorStatusCode _code;

        public ErrorStatusCode Code
        {
            get { return _code; }
            set
            {
                if(Equals(value, _code))return;
                _code = value;
                Msg = EnumUtil.GetDescription(_code);
            }
        }

        public string Msg { get; private set; }

        public string Request { get; set; }
    }

    /// <summary>
    /// 不成功代码
    /// </summary>
    public enum ErrorStatusCode
    {
        /// <summary>
        /// 错误的请求协议
        /// </summary>
        [Description("错误的请求协议")]
        Invalid_Request_Scheme = 100,

        /// <summary>
        /// 错误的请求方法
        /// </summary>
        [Description("错误的请求方法")]
        Invalid_Request_Method = 101,

        /// <summary>
        /// 未找到access_token
        /// </summary>
        [Description("未找到access_token")]
        Access_Token_Is_Missing = 102,

        /// <summary>
        /// access_token 不存在或已被用户删除，或者用户修改了密码
        /// </summary>
        [Description("access_token 不存在或已被用户删除，或者用户修改了密码")]
        Invalid_Access_Token = 103,

        /// <summary>
        /// API Key 不存在或已删除
        /// </summary>
        [Description("API Key 不存在或已删除")]
        Invalid_ApiKey = 104,

        /// <summary>
        /// apikey 已被禁用
        /// </summary>
        [Description("apikey 已被禁用")]
        ApiKey_Is_Blocked = 105,

        /// <summary>
        /// access_token 已过期
        /// </summary>
        [Description("access_token 已过期")]
        Access_Token_Has_Expired = 106,

        /// <summary>
        /// 请求地址未注册
        /// </summary>
        [Description("请求地址未注册")]
        InValid_Request_Url = 107,

        /// <summary>
        /// 用户未授权访问此数据
        /// </summary>
        [Description("用户未授权访问此数据")]
        Invalid_Credencial1 = 108,

        /// <summary>
        /// apikey 未申请此权限
        /// </summary>
        [Description("apikey 未申请此权限")]
        Invalid_Credencial2 = 109,

        /// <summary>
        /// 未注册的测试用户
        /// </summary>
        [Description("未注册的测试用户")]
        Not_Trial_User = 110,

        /// <summary>
        /// 用户访问速度限制
        /// </summary>
        [Description("用户访问速度限制")]
        Rate_Limit_Exceeded1 = 111,

        /// <summary>
        /// IP 访问速度限制
        /// </summary>
        [Description("IP 访问速度限制")]
        Rate_Limit_Exceeded2 = 112,

        /// <summary>
        ///  缺少参数
        /// </summary>
        [Description("缺少参数")]
        Required_Parameter_Is_Missing = 113,

        /// <summary>
        /// 错误的 grant_type
        /// </summary>
        [Description("错误的 grant_type")]
        Unsupported_Grant_Type = 114,

        /// <summary>
        /// 错误的 response_type
        /// </summary>
        [Description("错误的 response_type")]
        Unsupported_Response_Type = 115,

        /// <summary>
        /// client_secret不匹配
        /// </summary>
        [Description("client_secret不匹配")]
        Client_Secret_Mismatch = 116,

        /// <summary>
        /// redirect_uri不匹配
        /// </summary>
        [Description("redirect_uri不匹配")]
        Redirect_Uri_Mismatche = 117,

        /// <summary>
        /// authorization_code 不存在或已过期
        /// </summary>
        [Description("authorization_code 不存在或已过期")]
        Invalid_Authorization_Code = 118,

        /// <summary>
        /// refresh_token 不存在或已过期
        /// </summary>
        [Description("refresh_token 不存在或已过期")]
        Invalid_Refresh_Token = 119,

        /// <summary>
        /// 用户名密码不匹配
        /// </summary>
        [Description("用户名密码不匹配")]
        Username_Password_Mismatch = 120,

        /// <summary>
        /// 用户不存在或已删除
        /// </summary>
        [Description("用户不存在或已删除")]
        Invalid_User = 121,

        /// <summary>
        /// 用户已被屏蔽
        /// </summary>
        [Description("用户已被屏蔽")]
        User_Has_Blocked = 122,

        /// <summary>
        /// 因用户修改密码而导致 access_token 过期
        /// </summary>
        [Description("因用户修改密码而导致 access_token 过期")]
        Access_Token_Has_Expired_Since_Password_Changed = 123,

        /// <summary>
        /// access_token 未过期
        /// </summary>
        [Description("access_token 未过期")]
        Access_Token_Has_Not_Expired = 124,

        /// <summary>
        /// 访问的 scope 不合法，开发者不用太关注，一般不会出现该错误
        /// </summary>
        [Description("访问的 scope 不合法")]
        Invalid_Request_Scope = 125,


        /// <summary>
        /// 访问来源不合法
        /// </summary>
        [Description("访问来源不合法")]
        Invalid_Request_Source = 126,

        /// <summary>
        /// 第三方授权错误
        /// </summary>
        [Description("第三方授权错误")]
        Thirdparty_Login_Auth_Failed = 127,

        /// <summary>
        /// 用户被锁定
        /// </summary>
        [Description("用户被锁定")]
        User_Locked = 128,

        /// <summary>
        /// 未知错误
        /// </summary>
        [Description("未知错误")]
        Unknown = 999,
    }
}

